package com.example.mydianping.utils;

import com.example.mydianping.dto.UserDTO;
import com.example.mydianping.pojo.User;

public class UserHolder {

    //user 对应的的线程池
    private static final ThreadLocal<UserDTO> tl = new ThreadLocal<>();

    //往线程池中存入用户
    public static void saveUser(UserDTO user){
        tl.set(user);
    }

    //拿到当前线程的 user,一个线程只有一个 user
    public static UserDTO getUser(){
        return tl.get();
    }

    //移除当前线程的 user
    public static void removeUser(){
        tl.remove();
    }

}
